package com.sitc.street_lab_2013;

import android.R;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class HomeImageScrollAdapter extends PagerAdapter {

	private final int[] images = new int[] {
			R.drawable.alert_dark_frame,
			R.drawable.checkbox_on_background,
			R.drawable.dialog_frame
	};

	private Context context;

	public HomeImageScrollAdapter(Context context){
		this.context=context;
	}

	@Override
	public int getCount() {
		return images.length;
	}

	@Override
	public boolean isViewFromObject(View view, Object obj) {
		return view == ((ImageView) obj);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((ImageView) object);
	}

	@Override
	public Object instantiateItem(View container, int position) {
		ImageView imageView = new ImageView(context);
		int padding = context.getResources().getDimensionPixelSize(1);
		imageView.setPadding(padding, padding, padding, padding);
		imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		imageView.setImageResource(images[position]);
		((ViewPager) container).addView(imageView, 0);
		return imageView;
	}
}
